﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CAEXObjectWithAttributesViewModel.cs" >
//   J. Prinz
// </copyright>
// <summary>
//   ViewModel for the representation of any CaexObject which has Attributes
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AutomationMLMapper.ViewModels.CAEXObjectViewModels
{
    using CAEX_ClassModel;

    using AutomationMLMapper.ViewModels.CAEXObjectCollectionViewModels;

    /// <summary>
    /// ViewModel for the representation of any CaexObject which has Attributes
    /// </summary>
    /// <typeparam name="T">
    /// a Type, which implements <see cref="IObjectWithAttributes"/>
    /// </typeparam>
    public class CAEXObjectWithAttributesViewModel<T> : CAEXObjectViewModel<T>
        where T : CAEXObject, IObjectWithAttributes
    {
        #region Constructors and Destructors

        /// <summary>
        ///  Initializes a new instance of the <see cref="CAEXObjectWithAttributesViewModel{T}"/> class. 
        /// </summary>
        /// <param name="caexObject">
        ///  a CAEX-Element 
        /// </param>
        public CAEXObjectWithAttributesViewModel(T caexObject)
            : base(caexObject)
        {
            this.AttributesCollection = new AttributeCollectionViewModel(this) { IsExpanded = false };
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///   Collection of Attributes of the Class
        /// </summary>
        public AttributeCollectionViewModel AttributesCollection { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///   load method will load all attributes of the CaexObject and add them to the AttributesCollection <seealso
        ///    cref="AttributesCollection" />
        /// </summary>
        public override void LoadCaexToRepresentationModel()
        {
            base.LoadCaexToRepresentationModel();
            foreach (AttributeType attribute in this.CaexObject.getAttributeField())
            {
                var attributeRepresentation = new AttributeViewModel(attribute);
                attributeRepresentation.LoadCaexToRepresentationModel();
                this.AttributesCollection.Elements.Add(attributeRepresentation);
            }
        }

        #endregion
    }
}